package com.cy.pj.sys.service.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
/*
 * 1.切入点
 * 2.通知*/
public class SysLogAspect {
    @Pointcut("bean(menuServiceImpl)")
    public void log() {//无所谓，只用于承载PointCut

    }

    /*
     * @param jointpoint
     * @return 返回值
     * @throws Throwable*/
    @Around("log()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        long t1 = System.currentTimeMillis();
        log.info("", t1);
        try {
            Object result = joinPoint.proceed();
            long t2 = System.currentTimeMillis();
            log.info("", t2);
            return result;
        } catch (Throwable e) {
            log.error(e.getMessage());
            throw e;
        }
    }
}
